package semiOrderedPermutation;

public class Solution {
    public int semiOrderedPermutation(int[] nums) {
        // 半有序排列
        int a = 0;
        int b = 0;
        int n = nums.length;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] == 1)a = i;
            if(nums[i] == nums.length)b = i;
        }
        return a>b?a+n-b-2:a+n-b-1;
    }
}
